
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>乘除法功能单元 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="4AXI4总线.html" />
    
    
    <link rel="prev" href="2五级流水.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">前言</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">BoomV3</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../../BoomCode/chipyard-install.html">
            
                <a href="../../BoomCode/chipyard-install.html">
            
                    
                    Chipyard 1.8.0安装教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../../BoomCode/boom-debug.html">
            
                <a href="../../BoomCode/boom-debug.html">
            
                    
                    Boom调试【更新中】
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">论文阅读</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../../paper_read/prefetch-guard.html">
            
                <a href="../../paper_read/prefetch-guard.html">
            
                    
                    Prefetch-guard
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Gem5 学习</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../../gem5/gem5_fs.html">
            
                <a href="../../gem5/gem5_fs.html">
            
                    
                    X86 全系统模式模拟
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../../gem5/custom_disk_img.html">
            
                <a href="../../gem5/custom_disk_img.html">
            
                    
                    自定义磁盘镜像
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">一生一芯FangCore实现</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="1单周期CPU.html">
            
                <a href="1单周期CPU.html">
            
                    
                    单周期CPU实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="2五级流水.html">
            
                <a href="2五级流水.html">
            
                    
                    顺序五级流水CPU设计
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="5.3" data-path="3乘除法器.html">
            
                <a href="3乘除法器.html">
            
                    
                    乘除法功能单元
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="4AXI4总线.html">
            
                <a href="4AXI4总线.html">
            
                    
                    AXI4总线
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="5高速缓存Cache.html">
            
                <a href="5高速缓存Cache.html">
            
                    
                    高速缓存Cache设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="6中断异常.html">
            
                <a href="6中断异常.html">
            
                    
                    简单的中断异常支持
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="7分支预测器.html">
            
                <a href="7分支预测器.html">
            
                    
                    分支预测器
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >乘除法功能单元</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x4E58;&#x9664;&#x6CD5;&#x529F;&#x80FD;&#x5355;&#x5143;">&#x4E58;&#x9664;&#x6CD5;&#x529F;&#x80FD;&#x5355;&#x5143;</h1>
<h2 id="&#x53C2;&#x8003;&#x8D44;&#x6599;&#xFF08;&#x63D0;&#x524D;&#x9605;&#x8BFB;&#xFF09;">&#x53C2;&#x8003;&#x8D44;&#x6599;&#xFF08;&#x63D0;&#x524D;&#x9605;&#x8BFB;&#xFF09;</h2>
<blockquote>
<p>&#x300A;CPU&#x8BBE;&#x8BA1;&#x5B9E;&#x6218;&#x300B;&#x7B2C;&#x4E94;&#x7AE0;P140-P151</p>
<p>&#x300A;&#x8BA1;&#x7B97;&#x673A;&#x7EC4;&#x6210;&#x4E0E;&#x8BBE;&#x8BA1; &#x786C;&#x4EF6;&#x8F6F;&#x4EF6;&#x63A5;&#x53E3;&#xFF08;&#x7B2C;&#x4E94;&#x7248;&#xFF09;&#x300B;&#x7B2C;3&#x7AE0; P124-132</p>
<p>&#x300A;&#x8BA1;&#x7B97;&#x673A;&#x4F53;&#x7CFB;&#x57FA;&#x7840;&#x7ED3;&#x6784;&#x300B;<a href="https://foxsen.github.io/archbase/%E8%BF%90%E7%AE%97%E5%99%A8%E8%AE%BE%E8%AE%A1.html#%E5%AE%9A%E7%82%B9%E8%A1%A5%E7%A0%81%E4%B9%98%E6%B3%95%E5%99%A8" target="_blank">&#x5728;&#x7EBF;&#x7248;</a></p>
</blockquote>
<h2 id="1&#x3001;riscv&#x4E2D;&#x7684;&#x4E58;&#x9664;&#x6CD5;&#x6307;&#x4EE4;&#xFF08;rv64m&#xFF09;">1&#x3001;RISCV&#x4E2D;&#x7684;&#x4E58;&#x9664;&#x6CD5;&#x6307;&#x4EE4;&#xFF08;RV64M&#xFF09;</h2>
<p>&#x8BA1;&#x7B97;&#x5668;&#x5B58;&#x50A8;&#x6570;&#x636E;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x90FD;&#x662F;&#x4EE5;&#x8865;&#x7801;&#x7684;&#x5F62;&#x5F0F;&#x8FDB;&#x884C;&#x7684;&#x3002;&#x56E0;&#x6B64;&#x8F93;&#x5165;&#x5230;&#x4E58;&#x9664;&#x6CD5;&#x5668;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x90FD;&#x662F;&#x8865;&#x7801;&#x5F62;&#x5F0F;&#xFF0C;&#x6709;&#x65E0;&#x7B26;&#x53F7;&#x5F71;&#x54CD;&#x5185;&#x90E8;&#x7684;&#x8FD0;&#x7B97;&#xFF0C;&#x6700;&#x7EC8;&#x7684;&#x7ED3;&#x679C;&#x4E5F;&#x4F1A;&#x4EE5;&#x8865;&#x7801;&#x5F62;&#x5F0F;&#x8FD4;&#x56DE;&#x3002;</p>
<h3 id="&#x4E58;&#x6CD5;&#x6307;&#x4EE4;">&#x4E58;&#x6CD5;&#x6307;&#x4EE4;</h3>
<p>&#x79EF;&#x7684;&#x957F;&#x5EA6;&#x662F;&#x4E58;&#x6570;&#x548C;&#x88AB;&#x4E58;&#x6570;&#x957F;&#x5EA6;&#x7684;&#x548C;&#x3002;&#x5C06;&#x4E24;&#x4E2A;64&#x4F4D;&#x6570;&#x76F8;&#x4E58;&#x5F97;&#x5230;&#x7684;&#x662F; 128&#x4F4D;&#x7684;&#x4E58;&#x79EF;&#x3002;&#x4E3A;&#x4E86;&#x6B63;&#x786E;&#x5730;&#x5F97;&#x5230;&#x4E00;&#x4E2A;&#x6709;&#x7B26;&#x53F7;&#x6216;&#x65E0;&#x7B26;&#x53F7;&#x7684; 64&#x4F4D;&#x79EF;&#x3002;&#x8981;&#x5F97;&#x5230;&#x6574;&#x6570; 64&#x4F4D;&#x4E58;&#x79EF;&#xFF08; 128&#x4F4D;&#x4E2D;&#x7684;&#x4F4E; 64&#x4F4D;&#xFF09;&#x5C31;&#x7528; <strong>mul</strong>&#x6307;&#x4EE4;&#x3002;&#x8981;&#x5F97;&#x5230;&#x9AD8; 32&#x4F4D;&#xFF0C;&#x5982;&#x679C;&#x64CD;&#x4F5C;&#x6570;&#x90FD;&#x662F;&#x6709;&#x7B26;&#x53F7;&#x6570;&#xFF0C;&#x5C31;&#x7528; <strong>mulh</strong>&#x6307;&#x4EE4;&#xFF1B;&#x5982;&#x679C;&#x64CD;&#x4F5C;&#x6570;&#x90FD;&#x662F;&#x65E0;&#x7B26;&#x53F7;&#x6570;&#xFF0C;&#x5C31;&#x7528; <strong>mulhu</strong>&#x6307;&#x4EE4;&#xFF1B;&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x6709;&#x7B26;&#x53F7;&#x4E00;&#x4E2A;&#x65E0;&#x7B26;&#x53F7;&#xFF0C;&#x53EF;&#x4EE5;&#x7528; <strong>mulhsu</strong>&#x6307;&#x4EE4;&#x3002;&#x5728;&#x4E00;&#x6761;&#x6307;&#x4EE4;&#x4E2D;&#x5B8C;&#x6210;&#x628A; 128&#x4F4D;&#x79EF;&#x5199;&#x5165;&#x4E24;&#x4E2A; 64&#x4F4D;&#x5BC4;&#x5B58;&#x5668;&#x7684;&#x64CD;&#x4F5C;&#x4F1A;&#x4F7F;&#x786C;&#x4EF6;&#x8BBE;&#x8BA1;&#x53D8;&#x5F97;&#x590D;&#x6742;&#xFF0C;&#x6240;&#x4EE5; RV64M&#x9700;&#x8981;&#x4E24;&#x6761;&#x4E58;&#x6CD5;&#x6307;&#x4EE4;&#x624D;&#x80FD;&#x5F97;&#x5230;&#x4E00;&#x4E2A;&#x5B8C;&#x6574;&#x7684;128&#x4F4D;&#x79EF;&#x3002;</p>
<p>&#x5C3D;&#x7BA1; RV64I&#x6709; 64&#x4F4D;&#x5730;&#x5740;&#x4E14;&#x9ED8;&#x8BA4;&#x6570;&#x636E;&#x5927;&#x5C0F;&#x4E3A; 64&#x4F4D;&#xFF0C; 32&#x4F4D;&#x5B57;&#x4ECD;&#x7136;&#x662F;&#x7A0B;&#x5E8F;&#x4E2D;&#x7684;&#x6709;&#x6548;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x3002;<strong>mulw</strong>&#x662F;RV64M&#x4E2D;&#x6DFB;&#x52A0;&#x7684;&#x5BF9;32&#x4F4D;&#x4E58;&#x6CD5;&#x7684;&#x652F;&#x6301;&#x3002;</p>
<table>
<thead>
<tr>
<th>&#x6307;&#x4EE4;</th>
<th>&#x63CF;&#x8FF0;</th>
<th>&#x6709;&#x65E0;&#x7B26;&#x53F7;</th>
<th>&#x884C;&#x4E3A;</th>
</tr>
</thead>
<tbody>
<tr>
<td>mul</td>
<td>&#x4E58;</td>
<td>x[rs1]&#x3001; x[rs2]&#x5747;&#x4E3A;&#x6709;&#x7B26;&#x53F7;&#x6570;</td>
<td>&#x4E58;&#x79EF;&#x5199;&#x5165; x[rd]</td>
</tr>
<tr>
<td>mulh</td>
<td>&#x9AD8;&#x4F4D;&#x4E58;&#x3002;</td>
<td>x[rs1]&#x3001; x[rs2]&#x5747;&#x4E3A;&#x6709;&#x7B26;&#x53F7;&#x6570;</td>
<td>&#x4E58;&#x79EF;&#x7684;<strong>&#x9AD8;&#x4F4D;</strong>&#x5199;&#x5165; x[rd]</td>
</tr>
<tr>
<td>mulhsu</td>
<td>&#x9AD8;&#x4F4D;&#x6709;&#x7B26;&#x53F7;-&#x65E0;&#x7B26;&#x53F7;&#x4E58;&#x3002;</td>
<td>x[rs1]&#x89C6;&#x4E3A;&#x6709;&#x7B26;&#x53F7;&#xFF0C;x[rs2]&#x89C6;&#x4E3A;&#x65E0;&#x7B26;&#x53F7;&#x3002;</td>
<td>&#x5C06;&#x4E58;&#x79EF;&#x7684;<strong>&#x9AD8;&#x4F4D;</strong>&#x5199;&#x5165; x[rd]</td>
</tr>
<tr>
<td>mulhu</td>
<td>&#x9AD8;&#x4F4D;&#x65E0;&#x7B26;&#x53F7;&#x4E58;</td>
<td>x[rs1]&#x3001; x[rs2]&#x5747;&#x4E3A;&#x65E0;&#x7B26;&#x53F7;&#x6570;</td>
<td>&#x5C06;&#x4E58;&#x79EF;&#x7684;<strong>&#x9AD8;&#x4F4D;</strong>&#x5199;&#x5165; x[rd]</td>
</tr>
<tr>
<td>mulw</td>
<td>&#x4E58;&#x5B57;</td>
<td>x[rs1]&#x3001; x[rs2]&#x5747;&#x4E3A;&#x6709;&#x7B26;&#x53F7;&#x6570;</td>
<td>&#x4E58;&#x79EF;&#x622A;&#x4E3A; 32 &#x4F4D;&#xFF0C;&#x8FDB;&#x884C;&#x6709;&#x7B26;&#x53F7;&#x6269;&#x5C55;&#x540E;&#x5199;&#x5165; x[rd]</td>
</tr>
</tbody>
</table>
<h3 id="&#x9664;&#x6CD5;&#x6307;&#x4EE4;">&#x9664;&#x6CD5;&#x6307;&#x4EE4;</h3>
<p>RV64M &#x5177;&#x6709;&#x6709;&#x7B26;&#x53F7;&#x548C;&#x65E0;&#x7B26;&#x53F7;&#x6574;&#x6570;&#x7684;&#x9664;&#x6CD5;&#x6307;&#x4EE4;&#xFF1A;divide(div)&#x548C;divide unsigned(divu)&#xFF0C;&#x5B83;&#x4EEC;&#x5C06;&#x5546;&#x653E;&#x5165;&#x76EE;&#x6807;&#x5BC4;&#x5B58;&#x5668;&#x3002;&#x5728;&#x5C11;&#x6570;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x7A0B;&#x5E8F;&#x5458;&#x9700;&#x8981;&#x4F59;&#x6570;&#x800C;&#x4E0D;&#x662F;&#x5546;&#xFF0C;&#x56E0;&#x6B64;RV64M &#x63D0;&#x4F9B;remainder(rem)&#x548C;remainder unsigned(remu)&#xFF0C;&#x5B83;&#x4EEC;&#x5728;&#x76EE;&#x6807;&#x5BC4;&#x5B58;&#x5668;&#x5199;&#x5165;&#x4F59;&#x6570;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x5546;&#x3002;&#x540C;&#x65F6;&#x4E3A;&#x4E86;&#x652F;&#x6301;32&#x4F4D;&#x7684;&#x9664;&#x6CD5;&#xFF0C;&#x8FD8;&#x6DFB;&#x52A0;&#x4E86;divw&#x3001;divwu&#x3001;remw&#x3001;remwu&#x3002;</p>
<table>
<thead>
<tr>
<th>&#x6307;&#x4EE4;</th>
<th>&#x63CF;&#x8FF0;</th>
<th>&#x6709;&#x65E0;&#x7B26;&#x5408;</th>
<th>&#x884C;&#x4E3A;</th>
</tr>
</thead>
<tbody>
<tr>
<td>div</td>
<td>&#x7528;&#x5BC4;&#x5B58;&#x5668;x[rs1]&#x7684;&#x503C;&#x9664;&#x4EE5;&#x5BC4;&#x5B58;&#x5668; x[rs2]&#x7684;&#x503C;</td>
<td>&#x6709;&#x7B26;&#x53F7;&#x2797;&#x6709;&#x7B26;&#x53F7;</td>
<td>&#x628A;&#x5546;&#x5199;&#x5165; x[rd]</td>
</tr>
<tr>
<td>divu</td>
<td>&#x7528;&#x5BC4;&#x5B58;&#x5668;x[rs1]&#x7684;&#x503C;&#x9664;&#x4EE5; &#x5BC4;&#x5B58;&#x5668; x[rs2]&#x7684;&#x503C;</td>
<td>&#x65E0;&#x7B26;&#x53F7;&#x2797;&#x65E0;&#x7B26;&#x53F7;</td>
<td>&#x628A;&#x5546;&#x5199;&#x5165; x[rd]</td>
</tr>
<tr>
<td>rem</td>
<td>&#x6C42;&#x4F59;&#x6570;</td>
<td>&#x6709;&#x7B26;&#x53F7;&#xFF05;&#x6709;&#x7B26;&#x53F7;</td>
<td>&#x628A;&#x4F59;&#x6570;&#x5199;&#x5165; x[rd]</td>
</tr>
<tr>
<td>remu</td>
<td>&#x65E0;&#x7B26;&#x53F7;&#x6C42;&#x4F59;&#x6570;</td>
<td>&#x65E0;&#x7B26;&#x53F7;&#xFF05;&#x65E0;&#x7B26;&#x53F7;</td>
<td>&#x628A;&#x4F59;&#x6570;&#x5199;&#x5165; x[rd]</td>
</tr>
<tr>
<td>divw</td>
<td>&#x65E0;&#x7B26;&#x53F7;&#x5B57;&#x9664;&#x6CD5;&#x3002;x[rs1]&#x7684;&#x4F4E; 32&#x4F4D;&#x9664;&#x4EE5; &#x5BC4;&#x5B58;&#x5668; x[rs2]&#x7684;&#x4F4E; 32 &#x4F4D;</td>
<td>&#x6709;&#x7B26;&#x53F7;&#x2797;&#x6709;&#x7B26;&#x53F7;</td>
<td>&#x7ECF;<strong>&#x7B26;&#x53F7;&#x4F4D;&#x6269;&#x5C55;</strong>&#x7684; 32 &#x4F4D;&#x5546;&#x5199;&#x5165; x[rd]</td>
</tr>
<tr>
<td>divwu</td>
<td>&#x5B57;&#x9664;&#x6CD5;&#x3002;&#x5BC4;&#x5B58;&#x5668;x[rs1]&#x7684;&#x4F4E; 32&#x4F4D;&#x9664;&#x4EE5; &#x5BC4;&#x5B58;&#x5668; x[rs2]&#x7684;&#x4F4E; 32 &#x4F4D;</td>
<td>&#x65E0;&#x7B26;&#x53F7;&#x2797;&#x65E0;&#x7B26;&#x53F7;</td>
<td>&#x7ECF;<strong>&#x7B26;&#x53F7;&#x4F4D;&#x6269;&#x5C55;</strong>&#x7684; 32 &#x4F4D;&#x5546;&#x5199;&#x5165; x[rd]</td>
</tr>
<tr>
<td>remw</td>
<td>&#x5B57;&#x6C42;&#x4F59;&#x6570;</td>
<td>&#x6709;&#x7B26;&#x53F7;&#xFF05;&#x6709;&#x7B26;&#x53F7;</td>
<td>&#x7ECF;<strong>&#x7B26;&#x53F7;&#x4F4D;&#x6269;&#x5C55;</strong>&#x7684; 32 &#x4F4D;&#x4F59;&#x6570;&#x5199;&#x5165; x[rd]</td>
</tr>
<tr>
<td>remwu</td>
<td>&#x65E0;&#x7B26;&#x53F7;&#x5B57;&#x6C42;&#x4F59;&#x6570;</td>
<td>&#x65E0;&#x7B26;&#x53F7;&#xFF05;&#x65E0;&#x7B26;&#x53F7;</td>
<td>&#x7ECF;<strong>&#x7B26;&#x53F7;&#x4F4D;&#x6269;&#x5C55;</strong>&#x7684; 32 &#x4F4D;&#x4F59;&#x6570;&#x5199;&#x5165; x[rd]</td>
</tr>
</tbody>
</table>
<h2 id="2&#x3001;&#x7535;&#x8DEF;&#x7EA7;&#x4E58;&#x6CD5;&#x5668;">2&#x3001;&#x7535;&#x8DEF;&#x7EA7;&#x4E58;&#x6CD5;&#x5668;</h2>
<h3 id="21-&#x7B80;&#x5355;&#x539F;&#x7801;&#x79FB;&#x4F4D;&#x4E58;&#x6CD5;&#x5668;">2.1 &#x7B80;&#x5355;&#x539F;&#x7801;&#x79FB;&#x4F4D;&#x4E58;&#x6CD5;&#x5668;</h3>
<p>&#x5BF9;&#x4E8E;&#x5B9A;&#x70B9;&#x4E58;&#x6CD5;&#x5668;&#x800C;&#x8A00;&#xFF0C;&#x6700;&#x7B80;&#x5355;&#x7684;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#x5C31;&#x662F;&#x901A;&#x8FC7;&#x786C;&#x4EF6;&#x6765;&#x6A21;&#x62DF;&#x8F6F;&#x4EF6;&#x7684;&#x8FED;&#x4EE3;&#x64CD;&#x4F5C;&#xFF0C;&#x8FD9;&#x79CD;&#x4E58;&#x6CD5;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#x88AB;&#x79F0;&#x4E3A;&#x79FB;&#x4F4D;&#x52A0;&#x3002;</p>
<p><img src="https://cdn.jsdelivr.net/gh/fangjiangff/images/img/202208182052026.png" alt="image-20220803195228283" style="zoom:67%;"></p>
<h3 id="22-&#x4E24;&#x4F4D;booth&#x7F16;&#x7801;">2.2 &#x4E24;&#x4F4D;booth&#x7F16;&#x7801;</h3>
<p>&#x5BF9;&#x4E8E;64&#x4F4D;&#x4E58;&#x6CD5;&#x800C;&#x8A00;&#xFF0C;&#x9700;&#x8981;&#x5C06;64&#x4E2A;&#x90E8;&#x5206;&#x79EF;&#x76F8;&#x52A0;&#x624D;&#x80FD;&#x5F97;&#x5230;&#x7ED3;&#x679C;&#xFF0C;&#x5E26;&#x6765;&#x7684;&#x5EF6;&#x8FDF;&#x548C;&#x786C;&#x4EF6;&#x7684;&#x5F00;&#x9500;&#x5F88;&#x5927;&#x3002;&#x901A;&#x8FC7;&#x5F15;&#x5165;&#x4E24;&#x4F4D;Booth&#x7F16;&#x7801;&#x53EF;&#x4EE5;&#x663E;&#x8457;&#x964D;&#x4F4E;&#x51CF;&#x5C11;&#x52A0;&#x6CD5;&#x7684;&#x6B21;&#x6570;&#x3002;&#x5177;&#x4F53;&#x8BF7;&#x53C2;&#x8003;&#x300A;CPU&#x8BBE;&#x8BA1;&#x5B9E;&#x6218;&#x300B;P140&#x3002;&#x4E24;&#x4E2A;&#x6570;&#x8865;&#x7801;&#x7684;&#x4E58;&#x79EF;&#x5E76;&#x4E0D;&#x7B49;&#x79EF;&#x7684;&#x8865;&#x7801;&#xFF0C;&#x5373;$\left [ x &#xD7;  y \right ]&#x8865; != \left [ x \right ]&#x8865; &#xD7; \left [ y \right ]&#x8865;$&#x3002;&#x4E0B;&#x9762;&#x4EE5;&#x516B;&#x4F4D;&#x4E58;&#x6CD5;&#x4E3A;&#x4F8B;&#x3002;$\left [ y \right ]&#x8865; = y<em>{7}y</em>{6}\cdots y_{0}$&#x3002;&#x6B63;&#x786E;&#x7684;&#x662F;&#x5982;&#x4E0B;&#x516C;&#x5F0F;&#x7684;&#x9996;&#x884C;&#xFF0C;&#x5BF9;&#x540E;&#x534A;&#x90E8;&#x5206;&#x505A;&#x53D8;&#x5316;&#x3002;</p>
<p>$\begin{aligned}&amp; \left [ x &#xD7;  y \right ]&#x8865; = \left [ x \right ]&#x8865; &#xD7; &#xFF08;-y<em>{7}\times 2^{7}+y</em>{6}\times 2^{6}+\ldots +y<em>{1}\times 2^{1}+y</em>{0}\times 2^{0}&#xFF09;\ &amp;=  \left [ x \right ]&#x8865; &#xD7;((-2y<em>{7}\times 2^{6}+y</em>{6})\times 2^{6}+(y<em>{5}\times 2^{6}-2y</em>{5})\times 2^{4}+\ldots \ &amp;\quad +(y<em>{1}\times 2^{2}-2y</em>{1})\times 2^{0})+y<em>{0}\times 2^{0}+y</em>{-1}\times 2^{0})\ &amp;= \left [ x \right ]&#x8865; &#xD7; ((y<em>{5}+y</em>{6}-2y<em>{7})\times 2^{6}+(y</em>{3}+y<em>{4}-2y</em>{5})\times 2^{4}+\ldots +(y<em>{-1}+y</em>{0}-2y_{1})\times 2^{0})\end{aligned}$</p>
<p>Booth&#x7F16;&#x7801;&#x6BCF;&#x6B21;&#x626B;&#x63CF;&#x4E58;&#x6570;&#x7684;&#x4E09;&#x4F4D;&#x6765;&#x786E;&#x5B9A;&#x90E8;&#x5206;&#x79EF;&#x3002;booth&#x7F16;&#x7801;&#x89C4;&#x5219;&#x5982;&#x4E0B;</p>
<p><img src="https://cdn.jsdelivr.net/gh/fangjiangff/images/img/202208182052562.png" alt="image-20220803203934986" style="zoom: 67%;"></p>
<p>&#x8FD9;&#x6837;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x4E58;&#x79EF;&#x9879;&#x51CF;&#x5C11;&#x4E00;&#x534A;&#x3002;8&#x4F4D;&#x7684;&#x4E58;&#x6CD5;&#xFF0C;&#x901A;&#x8FC7;booth&#x7F16;&#x7801;&#x4EA7;&#x751F;4&#x4E2A;&#x90E8;&#x5206;&#x79EF;&#x3002;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x5F97;&#x5230;&#xFF0C;64&#x4F4D;&#x7684;&#x4E58;&#x6CD5;&#xFF0C;&#x901A;&#x8FC7;booth&#x7F16;&#x7801;&#x4EA7;&#x751F;32&#x4E2A;&#x90E8;&#x5206;&#x79EF;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x4F7F;&#x7528;31&#x6B21;&#x52A0;&#x6CD5;&#x3002;&#x52A0;&#x6CD5;&#x6B21;&#x6570;&#x4ECE;&#x539F;&#x6765;&#x7684;63&#x6B21;&#x52A0;&#x6CD5;&#xFF0C;&#x51CF;&#x5C11;&#x5230;31&#x6B21;&#xFF0C;&#x6781;&#x5927;&#x63D0;&#x9AD8;&#x4E86;&#x6548;&#x7387;&#x3002;</p>
<h3 id="23-chisel&#x5B9E;&#x73B0;&#x57FA;&#x4E8E;booth&#x7F16;&#x7801;&#x7684;&#x8865;&#x7801;&#x4E58;&#x6CD5;&#x5668;">2.3 Chisel&#x5B9E;&#x73B0;&#x57FA;&#x4E8E;Booth&#x7F16;&#x7801;&#x7684;&#x8865;&#x7801;&#x4E58;&#x6CD5;&#x5668;</h3>
<p>&#x53EF;&#x4EE5;&#x540C;&#x65F6;&#x7B97;&#x51FA;&#x6240;&#x6709;&#x7684;&#x90E8;&#x5206;&#x79EF;&#xFF0C;&#x7136;&#x540E;&#x8FDB;&#x884C;&#x52A0;&#x6CD5;&#x8FD0;&#x7B97;&#x5F97;&#x5230;&#x6700;&#x7EC8;&#x7684;&#x7ED3;&#x679C;&#x3002;&#x4F46;&#x662F;&#x8FD9;&#x91CC;&#x91C7;&#x7528;&#x79FB;&#x4F4D;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x6BCF;&#x4E00;&#x4E2A;&#x65F6;&#x949F;&#x5468;&#x671F;&#x5F97;&#x5230;&#x4E00;&#x4E2A;&#x90E8;&#x5206;&#x79EF;&#xFF0C;&#x6240;&#x4EE5;&#x4E00;&#x4E2A;&#x5468;&#x671F;&#x5185;&#x65E0;&#x6CD5;&#x5F97;&#x5230;&#x4E58;&#x6CD5;&#x5668;&#x3002;64&#x4F4D;&#x7684;&#x4E58;&#x6CD5;&#x9700;&#x8981;32&#x4E2A;&#x5468;&#x671F;&#x624D;&#x80FD;&#x5F97;&#x5230;&#x7ED3;&#x679C;&#xFF0C;&#x5728;&#x4E58;&#x6CD5;&#x5668;&#x8FDB;&#x884C;&#x8BA1;&#x7B97;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x9700;&#x8981;&#x505C;&#x987F;&#x53D6;&#x6307;&#x3001;&#x8BD1;&#x7801;&#x7EA7;&#x3002;&#x4E58;&#x6CD5;&#x5668;&#x6A21;&#x5757;&#x6DFB;&#x52A0;&#x63A5;&#x53E3;ready&#x3001;out_valid&#x4FE1;&#x53F7;&#xFF0C;&#x7528;&#x4E8E;&#x901A;&#x77E5;&#x6267;&#x884C;&#x7EA7;&#xFF0C;&#x4E58;&#x6CD5;&#x5668;&#x662F;&#x5426;&#x6B63;&#x5728;&#x8FD0;&#x7B97;&#x3001;&#x8F93;&#x51FA;&#x7684;&#x7ED3;&#x679C;&#x662F;&#x5426;&#x6709;&#x6548;&#x3002;</p>
<h4 id="&#x2460;&#x6A21;&#x5757;&#x63A5;&#x53E3;&#x4FE1;&#x53F7;">&#x2460;&#x6A21;&#x5757;&#x63A5;&#x53E3;&#x4FE1;&#x53F7;</h4>
<table>
<thead>
<tr>
<th>&#x4FE1;&#x53F7;&#x540D;</th>
<th>&#x7C7B;&#x578B;/&#x4F4D;&#x5BBD;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>&#x8F93;&#x5165;</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>mul_valid</td>
<td>Bool</td>
<td>&#x4E3A;&#x9AD8;&#x65F6;&#xFF0C;&#x8868;&#x793A;&#x5F53;&#x524D;EXEU&#x7EA7;&#x7684;&#x6307;&#x4EE4;&#x4E3A;&#x4E58;&#x6CD5;&#x6307;&#x4EE4;&#xFF0C;&#x9700;&#x8981;&#x8FDB;&#x884C;&#x4E58;&#x6CD5;&#x8FD0;&#x7B97;&#x3002;&#x8BE5;&#x4FE1;&#x53F7;&#x53EA;&#x9700;&#x8981;&#x7EF4;&#x6301;&#x4E00;&#x4E2A;&#x5468;&#x671F;&#x3002;</td>
</tr>
<tr>
<td>flush</td>
<td>Bool</td>
<td>&#x4E3A;&#x9AD8;&#x65F6;&#x3002;&#x53D6;&#x6D88;&#x4E58;&#x6CD5;&#xFF0C;&#x5373;&#x5C06;&#x4E58;&#x6CD5;&#x5668;&#x72B6;&#x6001;&#x7F6E;&#x4E3A;&#x521D;&#x59CB;&#x6001;</td>
</tr>
<tr>
<td>mul_signed</td>
<td>2&#x4F4D;</td>
<td>2&#x4E3A;&#x7F16;&#x7801;&#x3002;11&#xFF0C;&#x6709;&#x7B26;&#x53F7;&#xD7;&#x6709;&#x7B26;&#x53F7;&#xFF1B;10&#xFF0C;&#x6709;&#x7B26;&#x53F7;&#xD7;&#x65E0;&#x7B26;&#x53F7;&#xFF1B;00&#xFF0C;&#x65E0;&#x7B26;&#x53F7;&#xD7;&#x65E0;&#x7B26;&#x53F7;</td>
</tr>
<tr>
<td>multiplicand</td>
<td>64&#x4F4D;</td>
<td>&#x88AB;&#x4E58;&#x6570;&#xFF08;&#x64CD;&#x4F5C;&#x6570;1&#xFF0C;&#x4E0A;&#x8FF0;X&#xFF09;</td>
</tr>
<tr>
<td>multiplier</td>
<td>64&#x4F4D;</td>
<td>&#x4E58;&#x6570;&#xFF08;&#x64CD;&#x4F5C;&#x6570;2&#xFF0C;&#x4E0A;&#x8FF0;Y&#xFF09;</td>
</tr>
<tr>
<td><strong>&#x8F93;&#x51FA;</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>mul_ready</td>
<td>Bool</td>
<td>&#x4E58;&#x6CD5;&#x5668;&#x662F;&#x5426;&#x53EF;&#x7528;&#xFF0C;&#xFF08;&#x5982;&#x679C;&#x6B63;&#x5728;&#x8FD0;&#x7B97;&#xFF0C;&#x5219;&#x4E0D;&#x53EF;&#x7528;&#xFF09;</td>
</tr>
<tr>
<td>out_valid</td>
<td>Bool</td>
<td>&#x8F93;&#x51FA;&#x7684;&#x7ED3;&#x679C;&#x662F;&#x5426;&#x6709;&#x6548;</td>
</tr>
<tr>
<td>result_hi</td>
<td>64&#x4F4D;</td>
<td>&#x9AD8;64&#x4F4D;&#x7ED3;&#x679C;</td>
</tr>
<tr>
<td>result_lo</td>
<td>64&#x4F4D;</td>
<td>&#x4F4E;64&#x4F4D;&#x7ED3;&#x679C;</td>
</tr>
</tbody>
</table>
<h4 id="&#x2461;&#x6240;&#x9700;&#x7684;&#x5BC4;&#x5B58;&#x5668;">&#x2461;&#x6240;&#x9700;&#x7684;&#x5BC4;&#x5B58;&#x5668;</h4>
<p>&#x7531;&#x4E8E;&#x91C7;&#x7528;&#x79FB;&#x4F4D;&#x7684;&#x65B9;&#x5F0F;&#x65E0;&#x6CD5;&#x4E00;&#x4E2A;&#x5468;&#x671F;&#x5185;&#x83B7;&#x5F97;&#x4E58;&#x6CD5;&#x7ED3;&#x679C;&#x3002;&#x4E58;&#x6CD5;&#x5668;&#x6A21;&#x5757;&#x5185;&#x9700;&#x8981;&#x58F0;&#x660E;&#x5BC4;&#x5B58;&#x5668;&#x7528;&#x4E8E;&#x4FDD;&#x5B58;&#x4E2D;&#x95F4;&#x7ED3;&#x679C;&#xFF0C;&#x63D0;&#x4F9B;&#x7ED9;&#x4E0B;&#x4E00;&#x4E2A;&#x5468;&#x671F;&#x4F7F;&#x7528;&#x3002;&#x540C;&#x65F6;&#x5F15;&#x5165;&#x4E24;&#x4E2A;&#x72B6;&#x6001;&#x3002;</p>
<pre><code class="lang-scala">    <span class="hljs-keyword">val</span> is_mul_ready        = <span class="hljs-type">RegInit</span>(<span class="hljs-literal">true</span>.<span class="hljs-type">B</span>)<span class="hljs-comment">//&#x521D;&#x59CB;&#x5904;&#x4E8E;&#x7A7A;&#x95F2;&#x72B6;&#x6001;</span>
    <span class="hljs-keyword">val</span> is_out_valid        = <span class="hljs-type">RegInit</span>(<span class="hljs-literal">false</span>.<span class="hljs-type">B</span>)
    <span class="hljs-keyword">val</span> multiplicand_reg    = <span class="hljs-type">RegInit</span>(<span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-number">130.</span><span class="hljs-type">W</span>))<span class="hljs-comment">//65*2&#x88AB;&#x4E58;&#x6570;&#x5BC4;&#x5B58;&#x5668;</span>
    <span class="hljs-keyword">val</span> multiplier_reg      = <span class="hljs-type">RegInit</span>(<span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-number">67.</span><span class="hljs-type">W</span>))<span class="hljs-comment">// 65&#x4F4D;&#x4E58;&#x6CD5;&#xFF0C;&#x4E3A;&#x4E86;2&#x4F4D;booth&#xFF0C;&#x6700;&#x524D;&#x6700;&#x540E;&#x8865;&#x4E00;&#x4F4D;</span>
    <span class="hljs-keyword">val</span> result_reg          = <span class="hljs-type">RegInit</span>(<span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-number">130.</span><span class="hljs-type">W</span>))<span class="hljs-comment">//&#x7ED3;&#x679C;&#x5BC4;&#x5B58;&#x5668;</span>
    <span class="hljs-keyword">val</span> count               = <span class="hljs-type">RegInit</span>(<span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-number">8.</span><span class="hljs-type">W</span>))<span class="hljs-comment">//&#x8BA1;&#x6570;&#x5668;</span>

    <span class="hljs-keyword">val</span> state_idle :: state_calculate :: <span class="hljs-type">Nil</span> = <span class="hljs-type">Enum</span>(<span class="hljs-number">2</span>)
    <span class="hljs-keyword">val</span> mul_state           = <span class="hljs-type">RegInit</span>(state_idle)<span class="hljs-comment">//&#x521D;&#x59CB;&#x72B6;&#x6001;&#x4E3A;&#x7A7A;&#x95F2;</span>
</code></pre>
<p>&#x5F53;valid&#x4FE1;&#x53F7;&#x4E3A;&#x9AD8;&#xFF0C;&#x4E14;&#x4E58;&#x6CD5;&#x5668;&#x7A7A;&#x95F2;&#xFF08;ready&#x4E3A;&#x9AD8;&#xFF09;&#xFF0C;&#x5219;&#x63E1;&#x624B;&#x6210;&#x529F;&#x3002;&#x4E58;&#x6CD5;&#x5668;&#x4ECE;&#x7A7A;&#x95F2;&#x6001;&#x8F6C;&#x4E3A;&#x8BA1;&#x7B97;&#x72B6;&#x6001;&#xFF0C;&#x540C;&#x65F6;&#x8BBE;&#x7F6E;&#x5BC4;&#x5B58;&#x5668;&#x7684;&#x503C;</p>
<pre><code class="lang-scala">is(state_idle){<span class="hljs-comment">//&#x4E58;&#x6CD5;&#x5668;&#x7A7A;&#x95F2;&#xFF0C;&#x5207;&#x6362;&#x5230;&#x8FD0;&#x7B97;&#x72B6;&#x6001;</span>
    when(mul_valid){<span class="hljs-comment">//&#x8F93;&#x5165;&#x6709;&#x6548;&#x6570;&#x636E;</span>
        mul_state := state_calculate
        &#x2026;&#x2026;
    }
  &#x2026;&#x2026;
}
</code></pre>
<h4 id="&#x2462;&#x652F;&#x6301;&#x6709;&#x7B26;&#x53F7;&#x65E0;&#x7B26;&#x53F7;&#x6570;&#x4E58;&#x6CD5;">&#x2462;&#x652F;&#x6301;&#x6709;&#x7B26;&#x53F7;&amp;&#x65E0;&#x7B26;&#x53F7;&#x6570;&#x4E58;&#x6CD5;</h4>
<p>&#x4E3A;&#x4E86;&#x540C;&#x65F6;&#x652F;&#x6301;64&#x4F4D;&#x6709;&#x7B26;&#x53F7;&#x6570;&#x548C;&#x65E0;&#x7B26;&#x53F7;&#x6570;&#x3002;</p>
<ul>
<li><p>64&#x4F4D;&#x62D3;&#x5C55;&#x81F3;65&#x4F4D;&#xFF0C;&#x5177;&#x4F53;&#x64CD;&#x4F5C;&#xFF1A;</p>
</li>
<li><p>&#x65E0;&#x7B26;&#x53F7;&#x6570;&#xFF0C;&#x6700;&#x9AD8;&#x4F4D;&#x524D;&#x9762;&#x518D;&#x8865;&#x4E0A;&#x4E00;&#x4E2A;0&#xFF0C;&#x53EF;&#x4EE5;&#x628A;&#x5B83;&#x770B;&#x4F5C;&#x7B26;&#x53F7;&#x4F4D;&#x4E3A;0&#x7684;&#x6709;&#x7B26;&#x53F7;&#x6570;</p>
</li>
<li><p>&#x6709;&#x7B26;&#x53F7;&#x6570;&#xFF0C;&#x6700;&#x9AD8;&#x4F4D;&#x524D;&#x9762;&#x8865;&#x4E0A;&#x7B26;&#x53F7;&#x4F4D;&#xFF0C;&#x6570;&#x503C;&#x4E0D;&#x4F1A;&#x6539;&#x53D8;</p>
<p>&#x901A;&#x8FC7;&#x8FD9;&#x79CD;&#x6700;&#x9AD8;&#x4F4D;&#x524D;&#x518D;&#x8865;&#x4E0A;&#x4E00;&#x4F4D;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x628A;&#x65E0;&#x7B26;&#x53F7;&#x6570;&#x548C;&#x6709;&#x7B26;&#x53F7;&#x6570;&#x7684;&#x5904;&#x7406;&#x7EDF;&#x4E00;&#x8D77;&#x6765;&#x3002;&#x76F8;&#x5E94;&#x7684;64&#x4F4D;&#x6570;&#x7684;&#x4E58;&#x6CD5;&#x5C31;&#x62D3;&#x5C55;&#x6210;&#x4E86;65&#x4F4D;&#x4E58;&#x6CD5;&#x3002;</p>
<h4 id="&#x2463;&#x79FB;&#x4F4D;&#x8BA1;&#x7B97;">&#x2463;&#x79FB;&#x4F4D;&#x8BA1;&#x7B97;</h4>
</li>
<li><p>&#x6839;&#x636E;booth&#x7F16;&#x7801;&#x786E;&#x5B9A;&#x90E8;&#x5206;&#x79EF;&#x7684;&#x503C;option_tmp&#x3002;</p>
</li>
<li>&#x6839;&#x636E;&#x662F;&#x5426;&#x4E3A;&#x6709;&#x7B26;&#x53F7;&#x6570;&#xFF0C;&#x5BF9;option_tmp&#x8FDB;&#x884C;&#x7B26;&#x53F7;&#x62D3;&#x5C55;&#xFF0C;&#x6216;&#x8005;&#x65E0;&#x7B26;&#x53F7;&#x62D3;&#x5C55;&#xFF0C;&#x4F7F;&#x4E58;&#x79EF;&#x9879;&#x5BF9;&#x9F50;&#x3002;</li>
<li>&#x5C06;&#x90E8;&#x5206;&#x79EF;&#x7D2F;&#x52A0;&#x5230;&#x6700;&#x7EC8;&#x7684;&#x7ED3;&#x679C;&#x5BC4;&#x5B58;&#x5668;&#x4E0A;</li>
<li>&#x88AB;&#x4E58;&#x6570;&#x5BC4;&#x5B58;&#x5668;&#x5DE6;&#x79FB;&#xFF08;&#x5BF9;&#x5E94;2.2&#x8282;&#x4E2D;&#xFF0C;&#x5BF9;&#x5E94;X&#x4E58;&#x4EE5;2&#x7684;n&#x6B21;&#x65B9;&#xFF09;&#x3001;&#x4E58;&#x6570;&#x5BC4;&#x5B58;&#x5668;&#x53F3;&#x79FB;&#x4E24;&#x4F4D;&#xFF08;&#x6BCF;&#x6B21;&#x53D6;&#x6700;&#x4F4E;3&#x4F4D;&#x786E;&#x5B9A;&#x90E8;&#x5206;&#x79EF;&#xFF09;&#xFF0C;&#x4E3A;&#x4E0B;&#x4E00;&#x4E2A;&#x5468;&#x671F;&#x51C6;&#x5907;</li>
</ul>
<pre><code class="lang-scala"><span class="hljs-keyword">val</span> option_tmp = <span class="hljs-type">MuxLookup</span>(multiplier_reg(<span class="hljs-number">2</span>, <span class="hljs-number">0</span>), <span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-number">128.</span><span class="hljs-type">W</span>), <span class="hljs-type">Array</span>(
    <span class="hljs-string">&quot;b000&quot;</span>.<span class="hljs-type">U</span> -&gt; <span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-number">128.</span><span class="hljs-type">W</span>),
    <span class="hljs-string">&quot;b001&quot;</span>.<span class="hljs-type">U</span> -&gt; multiplicand_reg,
    <span class="hljs-string">&quot;b010&quot;</span>.<span class="hljs-type">U</span> -&gt; multiplicand_reg,
    <span class="hljs-string">&quot;b011&quot;</span>.<span class="hljs-type">U</span> -&gt; (multiplicand_reg &lt;&lt; <span class="hljs-number">1.</span><span class="hljs-type">U</span>),
    <span class="hljs-string">&quot;b100&quot;</span>.<span class="hljs-type">U</span> -&gt; (-(multiplicand_reg &lt;&lt; <span class="hljs-number">1.</span><span class="hljs-type">U</span>)),
    <span class="hljs-string">&quot;b101&quot;</span>.<span class="hljs-type">U</span> -&gt; (-multiplicand_reg),
    <span class="hljs-string">&quot;b110&quot;</span>.<span class="hljs-type">U</span> -&gt; (-multiplicand_reg),
    <span class="hljs-string">&quot;b111&quot;</span>.<span class="hljs-type">U</span> -&gt; <span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-number">128.</span><span class="hljs-type">W</span>)
))
<span class="hljs-keyword">val</span> option = <span class="hljs-type">Mux</span>(mul_signed(<span class="hljs-number">1</span>), <span class="hljs-type">SignExt</span>(option_tmp,<span class="hljs-number">130</span>), <span class="hljs-type">ZeroExt</span>(option_tmp,<span class="hljs-number">130</span>))<span class="hljs-comment">//&#x88AB;&#x4E58;&#x6570;&#x662F;&#x5426;&#x4E3A;&#x6709;&#x7B26;&#x53F7;</span>
result_reg := result_reg + option
multiplicand_reg := (multiplicand_reg &lt;&lt; <span class="hljs-number">2</span>)<span class="hljs-comment">//&#x88AB;&#x4E58;&#x6570;&#x5DE6;&#x79FB;&#x4E24;&#x4F4D;</span>
multiplier_reg := (multiplier_reg &gt;&gt; <span class="hljs-number">2</span>)<span class="hljs-comment">//&#x4E58;&#x6570;&#x53F3;&#x79FB;&#x4E24;&#x4F4D;</span>
</code></pre>
<h2 id="3&#x3001;&#x7535;&#x8DEF;&#x7EA7;&#x9664;&#x6CD5;&#x5668;">3&#x3001;&#x7535;&#x8DEF;&#x7EA7;&#x9664;&#x6CD5;&#x5668;</h2>
<p>64&#x4F4D;&#x9664;&#x6CD5;&#x7684;&#x5546;&#x6700;&#x591A;&#x4E3A;64&#x4F4D;&#x3002;&#x53EF;&#x4EE5;&#x4F9D;&#x6B21;&#x4ECE;&#x5546;&#x7684;&#x7B2C;63&#x4F4D;&#x5230;0&#x4F4D;&#x5C1D;&#x8BD5;0&#x6216;&#x8005;1&#xFF0C;&#x8FD9;&#x4E0E;&#x7B14;&#x7B97;&#x65B9;&#x6CD5;&#x7C7B;&#x4F3C;&#x3002;&#x540C;&#x6837;&#x7684;&#xFF0C;&#x4F7F;&#x7528;&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#x65E0;&#x6CD5;&#x5728;&#x4E00;&#x4E2A;&#x5468;&#x671F;&#x5185;&#x5B8C;&#x6210;&#x9664;&#x6CD5;&#x8FD0;&#x884C;&#x3002;</p>
<h3 id="31&#x9664;&#x6CD5;&#x5668;&#x63A5;&#x53E3;">3.1&#x9664;&#x6CD5;&#x5668;&#x63A5;&#x53E3;</h3>
<table>
<thead>
<tr>
<th></th>
<th>&#x7C7B;&#x578B;/&#x4F4D;&#x5BBD;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>&#x8F93;&#x5165;</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>dividend</td>
<td>64</td>
<td>&#x88AB;&#x9664;&#x6570;</td>
</tr>
<tr>
<td>divisor</td>
<td>64</td>
<td>&#x9664;&#x6570;</td>
</tr>
<tr>
<td>div_valid</td>
<td>Bool</td>
<td>&#x5F00;&#x59CB;&#x4FE1;&#x53F7;.&#x4E3A;&#x9AD8;&#x8868;&#x793A;&#x8F93;&#x5165;&#x7684;&#x6570;&#x636E;&#x6709;&#x6548;</td>
</tr>
<tr>
<td>div_signed</td>
<td>Bool</td>
<td>&#x4E3A;&#x9AD8;&#xFF0C;&#x8868;&#x793A;&#x6709;&#x7B26;&#x53F7;&#x9664;&#x6CD5;</td>
</tr>
<tr>
<td>flush</td>
<td>Bool</td>
<td>&#x9AD8;&#x8868;&#x793A;&#x8981;&#x53D6;&#x6D88;&#x9664;&#x6CD5;</td>
</tr>
<tr>
<td><strong>&#x8F93;&#x51FA;</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>div_ready</td>
<td>Bool</td>
<td>&#x4E3A;&#x9AD8;&#x8868;&#x793A;&#x9664;&#x6CD5;&#x5668;&#x7A7A;&#x95F2;&#xFF0C;&#x53EF;&#x4EE5;&#x8F93;&#x5165;&#x6570;&#x636E;</td>
</tr>
<tr>
<td>out_valid</td>
<td>Bool</td>
<td>&#x4E3A;&#x9AD8;&#x8868;&#x793A;&#x9664;&#x6CD5;&#x5668;&#x8F93;&#x51FA;&#x4E86;&#x6709;&#x6548;&#x7ED3;&#x679C;</td>
</tr>
<tr>
<td>quotient</td>
<td>64</td>
<td>&#x5546;</td>
</tr>
<tr>
<td>remainder</td>
<td>64</td>
<td>&#x4F59;&#x6570;</td>
</tr>
</tbody>
</table>
<h3 id="32-&#x6240;&#x9700;&#x5BC4;&#x5B58;&#x5668;">3.2 &#x6240;&#x9700;&#x5BC4;&#x5B58;&#x5668;</h3>
<pre><code class="lang-scala">    <span class="hljs-keyword">val</span> reg_div_ready   = <span class="hljs-type">RegInit</span>(<span class="hljs-literal">true</span>.<span class="hljs-type">B</span>)<span class="hljs-comment">//&#x521D;&#x59CB;&#x5316;</span>
    <span class="hljs-keyword">val</span> reg_out_valid   = <span class="hljs-type">RegInit</span>(<span class="hljs-literal">false</span>.<span class="hljs-type">B</span>)

    <span class="hljs-keyword">val</span> dividend_r      = <span class="hljs-type">RegInit</span>(<span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-number">64.</span><span class="hljs-type">W</span>))<span class="hljs-comment">//&#x88AB;&#x9664;&#x6570;&#x5BC4;&#x5B58;&#x5668;</span>
    <span class="hljs-keyword">val</span> divisor_r       = <span class="hljs-type">RegInit</span>(<span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-number">64.</span><span class="hljs-type">W</span>))<span class="hljs-comment">//&#x9664;&#x6570;&#x5BC4;&#x5B58;&#x5668;</span>
    <span class="hljs-keyword">val</span> div_res_r       = <span class="hljs-type">RegInit</span>(<span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-number">64.</span><span class="hljs-type">W</span>))<span class="hljs-comment">//&#x5546;-&#x7ED3;&#x679C;&#x5BC4;&#x5B58;&#x5668;</span>
    <span class="hljs-keyword">val</span> rem_res_r       = <span class="hljs-type">RegInit</span>(<span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-number">64.</span><span class="hljs-type">W</span>))<span class="hljs-comment">//&#x4F59;&#x6570;-&#x7ED3;&#x679C;&#x5BC4;&#x5B58;&#x5668;</span>

    <span class="hljs-keyword">val</span> minuend         = <span class="hljs-type">RegInit</span>(<span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-number">64.</span><span class="hljs-type">W</span>))<span class="hljs-comment">//&#x88AB;&#x51CF;&#x6570;</span>
    <span class="hljs-keyword">val</span> invert_div_res  = <span class="hljs-type">RegInit</span>(<span class="hljs-literal">false</span>.<span class="hljs-type">B</span>)<span class="hljs-comment">//&#x662F;&#x5426;&#x53CD;&#x8F6C;</span>
    <span class="hljs-keyword">val</span> invert_rem_res  = <span class="hljs-type">RegInit</span>(<span class="hljs-literal">false</span>.<span class="hljs-type">B</span>)<span class="hljs-comment">//&#x662F;&#x5426;&#x53CD;&#x8F6C;</span>
</code></pre>
<h3 id="33-&#x7EDD;&#x5BF9;&#x503C;&#x8FED;&#x4EE3;&#x9664;&#x6CD5;&#x5668;&#x72B6;&#x6001;&#x673A;">3.3 &#x7EDD;&#x5BF9;&#x503C;&#x8FED;&#x4EE3;&#x9664;&#x6CD5;&#x5668;&#x72B6;&#x6001;&#x673A;</h3>
<p>&#x56DB;&#x79CD;&#x72B6;&#x6001;&#x548C;&#x8BA1;&#x6570;&#x5668;&#x7684;&#x58F0;&#x660E;</p>
<pre><code class="lang-scala">    <span class="hljs-keyword">val</span> state_idle :: state_start :: state_calculate :: state_end :: <span class="hljs-type">Nil</span> = <span class="hljs-type">Enum</span>(<span class="hljs-number">4</span>)
    <span class="hljs-keyword">val</span> div_state   = <span class="hljs-type">RegInit</span>(state_idle)
    <span class="hljs-keyword">val</span> count       = <span class="hljs-type">RegInit</span>(<span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-number">8.</span><span class="hljs-type">W</span>))
</code></pre>
<p>==&#x2460;&#x7A7A;&#x95F2;&#x72B6;&#x6001;&#xFF08;idle&#xFF09;==</p>
<p>&#x5F53;div_valid&#x65F6;&#xFF0C;&#x72B6;&#x6001;&#x5207;&#x6362;&#x4E3A;start&#xFF0C;&#x540C;&#x65F6;&#x521D;&#x59CB;&#x5316;&#xFF08;&#x590D;&#x4F4D;&#xFF09;&#x5BC4;&#x5B58;&#x5668;&#x7684;&#x503C;</p>
<pre><code class="lang-scala">is (state_idle) {
    when(io.div_valid){
        div_state := state_start
        reg_div_ready := <span class="hljs-literal">false</span>.<span class="hljs-type">B</span>
        reg_out_valid := <span class="hljs-literal">false</span>.<span class="hljs-type">B</span>  
        dividend_r := io.dividend
        divisor_r  := io.divisor
        &#x2026;&#x2026;&#x8BBE;&#x7F6E;&#x5176;&#x4ED6;&#x5BC4;&#x5B58;&#x5668;&#x7684;&#x503C;
    }
}
</code></pre>
<p>==&#x2461;&#x5F00;&#x59CB;&#x72B6;&#x6001;&#xFF08;start&#xFF09;==</p>
<p>&#x4E0D;&#x540C;&#x4E8E;&#x4E58;&#x6CD5;&#x8FD0;&#x7B97;&#x5668;&#x7684;&#x72B6;&#x6001;&#x673A;&#xFF0C;&#x9664;&#x4E86;&#x7A7A;&#x95F2;&#x548C;&#x8FD0;&#x7B97;&#x72B6;&#x6001;&#x5916;&#xFF0C;&#x65B0;&#x589E;&#x4E86;&#x5F00;&#x59CB;&#x548C;&#x7ED3;&#x675F;&#x72B6;&#x6001;&#x3002;&#x5F00;&#x59CB;&#x72B6;&#x6001;&#x7528;&#x4E8E;&#x5728;&#x8FD0;&#x7B97;&#x524D;&#x8FDB;&#x884C;&#x51C6;&#x5907;&#x5DE5;&#x4F5C;&#xFF0C;&#x5305;&#x62EC;&#x5982;&#x4E0B;&#x4E09;&#x70B9;</p>
<p>1&#xFF09;&#x5224;&#x65AD;&#x662F;&#x5426;&#x9664;&#x6570;&#x4E3A;0&#xFF0C;&#x5982;&#x679C;&#x662F;&#x76F4;&#x63A5;&#x5207;&#x6362;&#x5230;end&#x72B6;&#x6001;</p>
<p>2&#xFF09;&#x5904;&#x7406;&#x6709;&#x7B26;&#x53F7;&#x8D1F;&#x6570;&#xFF0C;&#x8BBE;&#x7F6E;&#x6B63;&#x786E;&#x7684;&#x88AB;&#x9664;&#x6570;dividend_r&#x3001;&#x9664;&#x6570;divisor_r&#x3001;&#x88AB;&#x51CF;&#x6570;minuend&#x5BC4;&#x5B58;&#x5668;&#x7684;&#x503C;</p>
<p>&#x88AB;&#x9664;&#x6570;&#x3001;&#x9664;&#x6570;&#x5BC4;&#x5B58;&#x5668;&#x4E2D;&#x5B58;&#x653E;&#x7684;&#x662F;&#x88AB;&#x9664;&#x6570;&#x548C;&#x9664;&#x6570;&#x7684;&#x7EDD;&#x5BF9;&#x503C;&#x3002;&#x7EDD;&#x5BF9;&#x503C;&#x7684;&#x786E;&#x5B9A;&#xFF1A;&#x65E0;&#x7B26;&#x53F7;&#x6570;&#xFF0C;&#x7EDD;&#x5BF9;&#x503C;&#x5C31;&#x662F;&#x672C;&#x8EAB;&#xFF1B;&#x6709;&#x7B26;&#x53F7;&#x6B63;&#x6570;&#xFF0C;&#x7EDD;&#x5BF9;&#x503C;&#x662F;&#x672C;&#x8EAB;&#xFF1B;&#x6709;&#x7B26;&#x53F7;&#x8D1F;&#x6570;&#xFF0C;&#x5BF9;&#x8865;&#x7801;&#x53D6;&#x53CD;&#x52A0;&#x4E00;&#xFF08;&#x4EE3;&#x7801;&#x4E2D;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x8D1F;&#x53F7;&#x5C31;&#x80FD;&#x6C42;&#x7EDD;&#x5BF9;&#x503C;&#xFF09;&#x3002;</p>
<p>&#x5176;&#x4E2D;&#x88AB;&#x51CF;&#x6570;&#x5BC4;&#x5B58;&#x5668;&#x4E2D;&#x503C;&#xFF0C;&#x662F;&#x7528;&#x6765;&#x653E;&#x7F6E;&#x6BCF;i&#x8F6E;&#x8FED;&#x4EE3;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x76EE;&#x524D;&#x88AB;&#x9664;&#x6570;&#x7684;&#x9AD8;i&#x4F4D;&#x3002;&#x7528;&#x4E8E;&#x548C;&#x9664;&#x6570;&#x6BD4;&#x8F83;&#x5927;&#x5C0F;&#x3002;&#xFF08;&#x6709;&#x70B9;&#x4E0D;&#x592A;&#x6E05;&#x9664;&#xFF09;&#x3002;&#x53EF;&#x4EE5;&#x53C2;&#x8003;&#x300A;CPU&#x8BBE;&#x8BA1;&#x5B9E;&#x6218;&#x300B;P148&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;&#x7B2C;&#x4E00;&#x8F6E;&#xFF0C;minuend=A[63:31]&#x3002;&#x7B2C;&#x4E8C;&#x8F6E;&#xFF0C;minuend=A[62:30]&#x3002;&#x3002;&#x3002;</p>
<p><img src="https://cdn.jsdelivr.net/gh/fangjiangff/images/img/202208182052051.png" alt="image-20220803225403161" style="zoom:30%;"></p>
<p>3&#xFF09;&#x5224;&#x65AD;&#x6700;&#x7EC8;&#x7ED3;&#x679C;&#x662F;&#x5426;&#x9700;&#x8981;&#x8C03;&#x6574;</p>
<ul>
<li><p>&#x4F59;&#x6570;&#x7684;&#x7B26;&#x53F7;&#x548C;&#x88AB;&#x9664;&#x6570;&#x7684;&#x7B26;&#x53F7;&#x4FDD;&#x6301;&#x4E00;&#x81F4;</p>
</li>
<li><p>&#x5F53;&#x88AB;&#x9664;&#x6570;&#x548C;&#x9664;&#x6570;&#x7B26;&#x53F7;&#x76F8;&#x540C;&#x65F6;&#xFF0C;&#x5546;&#x4E3A;&#x6B63;&#x3002;&#x5426;&#x5219;&#xFF0C;&#x5546;&#x4E3A;&#x8D1F;</p>
<p>&#x5728;&#x6574;&#x4E2A;&#x8FD0;&#x7B97;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x88AB;&#x9664;&#x6570;&#x3001;&#x9664;&#x6570;&#x5BC4;&#x5B58;&#x5668;&#x4E2D;&#x5B58;&#x653E;&#x7684;&#x90FD;&#x662F;&#x7EDD;&#x5BF9;&#x503C;&#xFF0C;&#x56E0;&#x6B64;&#x5982;&#x679C;&#x5546;&#x548C;&#x4F59;&#x6570;&#x7684;&#x7B26;&#x53F7;&#x4E3A;&#x8D1F;&#x6570;&#x65F6;&#xFF0C;&#x9700;&#x8981;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x8C03;&#x6574;&#x3002;</p>
</li>
</ul>
<pre><code class="lang-scala"><span class="hljs-keyword">val</span> dividend_invert     = (-dividend_r)
<span class="hljs-keyword">val</span> divisor_invert      = (-divisor_r) 
div_state       := state_calculate               
<span class="hljs-comment">//</span>
minuend := dividend_r(<span class="hljs-number">63</span>)

invert_rem_res := (io.div_signed &amp;&amp; dividend_r(<span class="hljs-number">63</span>) === <span class="hljs-string">&quot;b1&quot;</span>.<span class="hljs-type">U</span>)
<span class="hljs-comment">//&#x5546;&#x7684;&#x7ED3;&#x679C;&#x662F;&#x5426;&#x9700;&#x8981;&#x8C03;&#x6574;&#x3002;&#x9664;&#x6570;&#x548C;&#x88AB;&#x9664;&#x6570;&#x7B26;&#x53F7;&#x4E0D;&#x540C;&#x65F6;&#xFF0C;&#x5546;&#x7684;&#x7ED3;&#x679C;&#x4E3A;&#x8D1F;&#x6570;</span>
invert_div_res := (io.div_signed &amp;&amp; (dividend_r(<span class="hljs-number">63</span>)^divisor_r(<span class="hljs-number">63</span>) === <span class="hljs-string">&quot;b1&quot;</span>.<span class="hljs-type">U</span>))
</code></pre>
<p>==&#x2462;&#x8FD0;&#x7B97;&#x72B6;&#x6001;&#xFF08;calculate&#xFF09;==</p>
<p>&#x8FD0;&#x7B97;&#x72B6;&#x6001;&#xFF0C;&#x4E0D;&#x65AD;&#x66F4;&#x65B0;&#x7ED3;&#x679C;&#x5BC4;&#x5B58;&#x5668;&#x548C;&#x88AB;&#x51CF;&#x6570;&#x5BC4;&#x5B58;&#x5668;&#x7684;&#x503C;&#x3002;</p>
<pre><code class="lang-scala"><span class="hljs-keyword">val</span> minuend_sub_res = minuend - divisor_r
<span class="hljs-keyword">val</span> div_result_tmp = <span class="hljs-type">Mux</span>(minuend_ge_divisor, <span class="hljs-type">Cat</span>(div_res_r(<span class="hljs-number">62</span>,<span class="hljs-number">0</span>), <span class="hljs-number">1.</span><span class="hljs-type">U</span>), <span class="hljs-type">Cat</span>(div_res_r(<span class="hljs-number">62</span>,<span class="hljs-number">0</span>), <span class="hljs-number">0.</span><span class="hljs-type">U</span>))
<span class="hljs-keyword">val</span> minuend_tmp = <span class="hljs-type">Mux</span>(minuend_ge_divisor, minuend_sub_res(<span class="hljs-number">62</span>,<span class="hljs-number">0</span>), minuend(<span class="hljs-number">62</span>,<span class="hljs-number">0</span>))
&#x2026;&#x2026;
is(state_calculate){
    dividend_r  := <span class="hljs-type">Cat</span>(dividend_r(<span class="hljs-number">62</span>,<span class="hljs-number">0</span>), <span class="hljs-string">&quot;b0&quot;</span>.<span class="hljs-type">U</span>)<span class="hljs-comment">//&#x5DE6;&#x79FB;&#x4E00;&#x4F4D;</span>
    div_res_r   := div_result_tmp<span class="hljs-comment">//&#x66F4;&#x65B0;&#x8FD0;&#x7B97;&#x7ED3;&#x679C;</span>
    count       := count + <span class="hljs-number">1.</span><span class="hljs-type">U</span>(<span class="hljs-number">8.</span><span class="hljs-type">W</span>)
    when(count === <span class="hljs-number">63.</span><span class="hljs-type">U</span>(<span class="hljs-number">8.</span><span class="hljs-type">W</span>)){<span class="hljs-comment">//&#x9700;&#x8981;64&#x6B21;&#x8BA1;&#x7B97;</span>
        div_state   := state_end
        rem_res_r   := <span class="hljs-type">Mux</span>(minuend_ge_divisor, minuend_sub_res, minuend) <span class="hljs-comment">//&#x4F59;&#x6570;&#x7ED3;&#x679C;</span>
    }.otherwise{
        minuend     := <span class="hljs-type">Cat</span>(minuend_tmp(<span class="hljs-number">62</span>,<span class="hljs-number">0</span>), dividend_r(<span class="hljs-number">62</span>))<span class="hljs-comment">//&#x66F4;&#x65B0;&#x88AB;&#x51CF;&#x6570;</span>
    }
}
</code></pre>
<p>==&#x2463;&#x7ED3;&#x675F;&#x72B6;&#x6001;&#xFF08;end)==</p>
<p>&#x8C03;&#x6574;&#x6700;&#x7EC8;&#x7684;&#x5546;&#x548C;&#x4F59;&#x6570;&#x3002;&#x4FEE;&#x6539;&#x9664;&#x6CD5;&#x5668;&#x7684;&#x72B6;&#x6001;&#x5DF2;&#x7ECF;ready&#x548C;out_valid&#x4FE1;&#x53F7;&#x3002;</p>
<pre><code class="lang-scala">div_state       := state_idle
reg_div_ready   := <span class="hljs-literal">false</span>.<span class="hljs-type">B</span> 
reg_out_valid   := <span class="hljs-literal">true</span>.<span class="hljs-type">B</span>

div_res_r       := <span class="hljs-type">Mux</span>(invert_div_res, -div_res_r, div_res_r)
rem_res_r       := <span class="hljs-type">Mux</span>(invert_rem_res, -rem_res_r, rem_res_r)
</code></pre>
<h2 id="4&#x3001;&#x63A5;&#x5165;&#x6D41;&#x6C34;&#x7EBF;">4&#x3001;&#x63A5;&#x5165;&#x6D41;&#x6C34;&#x7EBF;</h2>
<p><img src="https://cdn.jsdelivr.net/gh/fangjiangff/images/img/202208182052114.png" alt="image-20220803231030474" style="zoom:50%;"></p>
<p>&#x5C06;&#x4E58;&#x6CD5;&#x5668;&#x548C;&#x9664;&#x6CD5;&#x5668;&#x5C01;&#x88C5;&#x6210;&#x4E58;&#x9664;&#x6CD5;&#x8FD0;&#x7B97;&#x6A21;&#x5757;MDU&#xFF0C;&#x8BE5;&#x6A21;&#x5757;&#x5185;&#xFF0C;&#xFF1A;</p>
<p>1&#xFF09;&#x6839;&#x636E;&#x5F53;&#x524D;&#x6307;&#x4EE4;&#x548C;&#x4E58;&#x9664;&#x6CD5;&#x5668;&#x72B6;&#x6001;&#xFF0C;&#x8BBE;&#x7F6E;&#x76F8;&#x5E94;&#x7684;valid&#x4FE1;&#x53F7;&#xFF0C;&#x8F93;&#x5165;&#x7ED9;&#x4E58;&#x9664;&#x6CD5;&#x5668;</p>
<pre><code class="lang-scala"><span class="hljs-keyword">val</span> boothM                       = <span class="hljs-type">Module</span>(<span class="hljs-keyword">new</span> <span class="hljs-type">BoothMultiplier</span>())
<span class="hljs-keyword">val</span> (mul_ready, mul_out_valid)   = (boothM.io.mul_ready, boothM.io.out_valid)
<span class="hljs-keyword">val</span> mul_valid          = is_mul &amp;&amp; !mul_doing &amp;&amp; !mul_out_valid    <span class="hljs-comment">/*&#x4E58;&#x6CD5;&#x5668;&#x63A5;&#x53D7;&#x6570;&#x636E;&#x4E4B;&#x540E;&#x5230;&#x4E0B;&#x4E00;&#x4E2A;&#x9664;&#x6CD5;&#x5230;&#x6765;&#x4E4B;&#x524D;&#xFF0C;mul_valid&#x90FD;&#x5E94;&#x8BE5;&#x662F;&#x96F6;*/</span>
when(mul_valid &amp;&amp; mul_ready){<span class="hljs-comment">//&#x63E1;&#x624B;&#x6210;&#x529F;</span>
    mul_doing := <span class="hljs-literal">true</span>.<span class="hljs-type">B</span>
}.elsewhen(mul_out_valid){<span class="hljs-comment">//&#x4E58;&#x6CD5;&#x5668;&#x8FD0;&#x7B97;&#x7ED3;&#x675F;</span>
    mul_doing := <span class="hljs-literal">false</span>.<span class="hljs-type">B</span>
}
</code></pre>
<p>2&#xFF09;&#x5224;&#x65AD;&#x4E58;&#x9664;&#x6CD5;&#x5668;&#x662F;&#x5426;&#x5FD9;&#x788C;&#xFF0C;&#x8BBE;&#x7F6E;mul_busy&#x3001;div_busy&#x3002;&#x5F53;&#x4E00;&#x65B9;&#x4E3A;&#x9AD8;&#x65F6;&#xFF0C;&#x8868;&#x793A;&#x6267;&#x884C;&#x7EA7;&#x6B63;&#x5FD9;&#xFF0C;&#x9700;&#x8981;&#x963B;&#x585E;&#x6D41;&#x6C34;&#x7EBF;</p>
<pre><code>val mul_busy         = is_mul &amp;&amp; !mul_out_valid
val div_busy         = is_div &amp;&amp; !div_out_valid
io.mdu_res      := Mux(is_mul, mul_res, div_res)
io.mdu_busy     := Mux(flush, false.B, (mul_busy | div_busy))
</code></pre><p>3&#xFF09;&#x6839;&#x636E;&#x5177;&#x4F53;&#x6307;&#x4EE4;&#xFF0C;&#x5904;&#x7406;&#x8F93;&#x5165;&#x5230;&#x4E58;&#x9664;&#x6CD5;&#x5668;&#x7684;&#x4FE1;&#x53F7;&#x3002;&#x5982;&#x662F;&#x5426;&#x6709;&#x7B26;&#x53F7;</p>
<p>&#x5F53;&#x6307;&#x4EE4;&#x4E3A;divw&#x3001;divwu&#x3001;remw&#x3001;remwu&#x65F6;&#xFF0C;&#x8FD8;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x8F93;&#x5165;&#x7ED9;&#x9664;&#x6CD5;&#x5355;&#x5143;&#x7684;&#x503C;&#xFF08;&#x4F7F;&#x5F97;64&#x4F4D;&#x9664;&#x6CD5;&#x5668;&#x652F;&#x6301;34&#x4F4D;&#x64CD;&#x4F5C;&#xFF1A;&#x64CD;&#x4F5C;&#x6570;&#x622A;&#x53D6;32&#x4F4D;&#xFF0C;&#x7B26;&#x53F7;&#x62D3;&#x5C55;\&#x96F6;&#x62D3;&#x5C55;&#x4E3A;64&#x4F4D;&#x540E;&#xFF0C;&#x4F7F;&#x7528;&#x652F;&#x6301;64&#x4F4D;&#x7684;&#x9664;&#x6CD5;&#x5668;&#x8FDB;&#x884C;&#x8FD0;&#x7B97;&#x3002;&#x6700;&#x7EC8;&#x5C06;&#x7ED3;&#x679C;&#x7684;&#x4F4E;32&#x4F4D;&#x7B26;&#x53F7;&#x62D3;&#x5C55;&#x4E3A;64&#x4F4D;&#xFF0C;&#x5199;&#x56DE;&#x5BC4;&#x5B58;&#x5668;&#x4E2D;&#xFF09;</p>
<pre><code class="lang-scala">div.io.dividend     := <span class="hljs-type">Mux</span>(isdivW, <span class="hljs-type">Mux</span>(is_signed, <span class="hljs-type">SignExt</span>(src1(<span class="hljs-number">31</span>,<span class="hljs-number">0</span>), <span class="hljs-number">64</span>), <span class="hljs-type">ZeroExt</span>(src1(<span class="hljs-number">31</span>,<span class="hljs-number">0</span>), <span class="hljs-number">64</span>)), src1)
div.io.divisor      := <span class="hljs-type">Mux</span>(isdivW, <span class="hljs-type">Mux</span>(is_signed, <span class="hljs-type">SignExt</span>(src2(<span class="hljs-number">31</span>,<span class="hljs-number">0</span>), <span class="hljs-number">64</span>), <span class="hljs-type">ZeroExt</span>(src2(<span class="hljs-number">31</span>,<span class="hljs-number">0</span>), <span class="hljs-number">64</span>)), src2)
</code></pre>
<p>4&#xFF09;&#x83B7;&#x53D6;&#x4E58;&#x9664;&#x6CD5;&#x5668;&#x7684;&#x8FD0;&#x7B97;&#x7ED3;&#x679C;&#xFF0C;&#x5E76;&#x6839;&#x636E;&#x5177;&#x4F53;&#x6307;&#x4EE4;&#x786E;&#x5B9A;&#x6700;&#x7EC8;MDU&#x5355;&#x5143;&#x7684;&#x503C;</p>
<ul>
<li>&#x4E58;&#x6CD5;&#x6307;&#x4EE4;&#x9700;&#x8981;&#x5224;&#x65AD;&#x5199;&#x56DE;&#x5BC4;&#x5B58;&#x5668;&#x7684;&#x503C;&#x662F;&#x9AD8;64&#x4F4D;&#x8FD8;&#x662F;&#x4F4E;64&#x4F4D;&#x3002;&#x8FD8;&#x8981;&#x5BF9;mulw&#x6307;&#x4EE4;&#x8FDB;&#x884C;&#x7279;&#x6B8A;&#x5904;&#x7406;</li>
<li>&#x9664;&#x6CD5;&#x6307;&#x4EE4;&#x9700;&#x8981;&#x5224;&#x65AD;&#x5199;&#x56DE;&#x5BC4;&#x5B58;&#x5668;&#x7684;&#x503C;&#x662F;&#x5546;&#x8FD8;&#x662F;&#x4F59;&#x6570;&#xFF0C;&#x9700;&#x8981;&#x5BF9;&#x5B57;&#x9664;&#x6CD5;&#x6307;&#x4EE4;&#x8FDB;&#x884C;&#x5904;&#x7406;</li>
</ul>
<pre><code class="lang-scala"><span class="hljs-keyword">val</span> mul_res = <span class="hljs-type">Mux</span>(mduOpType === <span class="hljs-string">&quot;b1000&quot;</span>.<span class="hljs-type">U</span>, <span class="hljs-type">SignExt</span>(lo_res(<span class="hljs-number">31</span>,<span class="hljs-number">0</span>),<span class="hljs-number">64</span>),<span class="hljs-comment">//mulw</span>
                    <span class="hljs-type">Mux</span>(<span class="hljs-type">MDUOpType</span>.sel_hi(mduOpType), hi_res, lo_res))

   <span class="hljs-keyword">val</span> div_res = <span class="hljs-type">LookupTreeDefault</span>(mduOpType, <span class="hljs-string">&quot;b0&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">64.</span><span class="hljs-type">W</span>), <span class="hljs-type">List</span>(
        <span class="hljs-type">MDUOpType</span>.div        -&gt; div.io.quotient,
        <span class="hljs-type">MDUOpType</span>.divu       -&gt; div.io.quotient,
        <span class="hljs-type">MDUOpType</span>.rem        -&gt; div.io.remainder,
        <span class="hljs-type">MDUOpType</span>.remu       -&gt; div.io.remainder,

        <span class="hljs-type">MDUOpType</span>.divw       -&gt; <span class="hljs-type">SignExt</span>(div.io.quotient(<span class="hljs-number">31</span>,<span class="hljs-number">0</span>), <span class="hljs-number">64</span>),
        <span class="hljs-type">MDUOpType</span>.divuw      -&gt; <span class="hljs-type">SignExt</span>(div.io.quotient(<span class="hljs-number">31</span>,<span class="hljs-number">0</span>), <span class="hljs-number">64</span>),
        <span class="hljs-type">MDUOpType</span>.remw       -&gt; <span class="hljs-type">SignExt</span>(div.io.remainder(<span class="hljs-number">31</span>,<span class="hljs-number">0</span>), <span class="hljs-number">64</span>),
        <span class="hljs-type">MDUOpType</span>.remuw      -&gt; <span class="hljs-type">SignExt</span>(div.io.remainder(<span class="hljs-number">31</span>,<span class="hljs-number">0</span>), <span class="hljs-number">64</span>)
    ))
    io.mdu_res      := <span class="hljs-type">Mux</span>(is_mul, mul_res, div_res)
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="2五级流水.html" class="navigation navigation-prev " aria-label="Previous page: 顺序五级流水CPU设计">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="4AXI4总线.html" class="navigation navigation-next " aria-label="Next page: AXI4总线">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"乘除法功能单元","level":"5.3","depth":1,"next":{"title":"AXI4总线","level":"5.4","depth":1,"path":"ysyx/FangCore/4AXI4总线.md","ref":"ysyx/FangCore/4AXI4总线.md","articles":[]},"previous":{"title":"顺序五级流水CPU设计","level":"5.2","depth":1,"path":"ysyx/FangCore/2五级流水.md","ref":"ysyx/FangCore/2五级流水.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"ysyx/FangCore/3乘除法器.md","mtime":"2022-09-25T12:02:49.405Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-04-12T09:28:35.525Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

